#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    //创建菜单栏
    QMenuBar *menuBar = new QMenuBar();
    this->setMenuBar(menuBar);

    //创建菜单
    QMenu *menu1 = new QMenu("文件(&F)");
    QMenu *menu2 = new QMenu("编辑(&E)");
    QMenu *menu3 = new QMenu("视图(&V)");
    menuBar->addMenu(menu1);
    menuBar->addMenu(menu2);
    menuBar->addMenu(menu3);

    //创建菜单项
    QAction *action1 = new QAction("新建(&C)");
    QAction *action2 = new QAction("打开(&O)");
    QAction *action3 = new QAction("退出(&Q)");

    menu1->addAction(action1);
    //插入空白行
    menu1->addSeparator();
    menu2->addAction(action2);
    menu3->addAction(action3);

    //创建子菜单
    QMenu *child = new QMenu("子菜单(&S)");
    menu1->addMenu(child);

    //为子菜单创建菜单项
    QAction *action4 = new QAction("action4(&J)");
    QAction *action5 = new QAction("action5(&l)");
    QAction *action6 = new QAction("action6(&K)");

    child->addAction(action4);
    child->addAction(action5);
    child->addAction(action6);

    //为菜单项绑定信号槽
    connect(action4,&QAction::triggered,this,&MainWindow::handle4);
    connect(action5,&QAction::triggered,this,&MainWindow::handle5);
    connect(action6,&QAction::triggered,this,&MainWindow::handle6);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle4()
{
    qDebug() << "action4";
}

void MainWindow::handle5()
{
    qDebug() << "action5";
}

void MainWindow::handle6()
{
    qDebug() << "action6";
}

